package com.colbby.datahouse.transform;

import com.colbby.datahouse.utils.TypeDescriptor;
import com.colbby.datahouse.utils.TypeUtils;

public class EnumTransformer implements DataTypeTransform<Enum> {

	public static final EnumTransformer INSTANCE = new EnumTransformer();
	
	@Override
	public Enum transform(TypeDescriptor returnType, Object value) {
		return (Enum) Enum.valueOf((Class<Enum>)returnType.getTypeClass(), value.toString());
	}

	@Override
	public boolean shouldDo(TypeDescriptor returnType, Object value) {
		return TypeUtils.isSuperClass(Enum.class, returnType.getTypeClass());
	}
	
}
